import matplotlib.pyplot as plt
import mplcursors
from mpl_toolkits.mplot3d import Axes3D
import random

'''
pip install mplcursors
'''

# Generate 100 random x, y, z values
x = [random.uniform(0, 10) for _ in range(100)]
y = [random.uniform(0, 10) for _ in range(100)]
z = [random.uniform(0, 10) for _ in range(100)]
w = [random.uniform(0, 10) for _ in range(100)]

x1 = [random.uniform(0, 10) for _ in range(100)]
y1 = [random.uniform(0, 10) for _ in range(100)]
z1 = [random.uniform(0, 10) for _ in range(100)]
w1 = [random.uniform(0, 10) for _ in range(100)]

# Create the figure and two subplots
fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'projection': '3d'})

# Plot the data on the first subplot
ax1.scatter(x, y, z)

# Add the cursor to the first subplot
cursor1 = mplcursors.cursor(ax1, hover=True)
@cursor1.connect("add")
def on_add1(sel):
    index = sel.target.index
    x, y, z = sel.artist._offsets3d
    sel.annotation.set_text(f"({x[index]:.2f}, {y[index]:.2f}, {z[index]:.2f})"+" w: "+str(w[index]))

# Plot the data on the second subplot
ax2.scatter(x1, y1, z1)

# Add the cursor to the second subplot
cursor2 = mplcursors.cursor(ax2, hover=True)
@cursor2.connect("add")
def on_add2(sel):
    index = sel.target.index
    x, y, z = sel.artist._offsets3d
    sel.annotation.set_text(f"({x[index]:.2f}, {y[index]:.2f}, {z[index]:.2f})"+" w: "+str(w1[index]))

# Show the plot
plt.show()